<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo_blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo_blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo_blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo_blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo_blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bone-nails.gitee.io","root":"/hexo_blog/","images":"/hexo_blog/images","scheme":"Gemini","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/hexo_blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":true}};
  </script>
<meta name="description" content="mysql的存储引擎介绍什么是数据库存储引擎？12数据库底层软件组件，不同的引擎提供不同的存储方式，索引技巧。事务使用InnoDB">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql的存储引擎和索引">
<meta property="og:url" content="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/index.html">
<meta property="og:site_name" content="Carson Zhao">
<meta property="og:description" content="mysql的存储引擎介绍什么是数据库存储引擎？12数据库底层软件组件，不同的引擎提供不同的存储方式，索引技巧。事务使用InnoDB">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416185307875.png">
<meta property="og:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416185353831.png">
<meta property="article:published_time" content="2021-04-12T05:26:22.000Z">
<meta property="article:modified_time" content="2021-04-19T03:58:23.903Z">
<meta property="article:author" content="Carson Zhao">
<meta property="article:tag" content="存储引擎和索引">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416185307875.png">


<link rel="canonical" href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>mysql的存储引擎和索引 | Carson Zhao</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/hexo_blog/atom.xml" title="Carson Zhao" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo_blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Carson Zhao</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/hexo_blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-about"><a href="/hexo_blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-tags"><a href="/hexo_blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-categories"><a href="/hexo_blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E4%BB%8B%E7%BB%8D"><span class="nav-number">1.</span> <span class="nav-text">mysql的存储引擎介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E6%95%B0%E6%8D%AE%E5%BA%93%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%EF%BC%9F"><span class="nav-number">1.1.</span> <span class="nav-text">什么是数据库存储引擎？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E6%9F%A5%E7%9C%8B%E6%94%AF%E6%8C%81%E7%9A%84%E5%BC%95%E6%93%8E"><span class="nav-number">1.2.</span> <span class="nav-text">如何查看支持的引擎</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%BB%BA%E8%A1%A8%E6%97%B6%E6%8C%87%E5%AE%9A%E5%BC%95%E6%93%8E"><span class="nav-number">1.3.</span> <span class="nav-text">建表时指定引擎</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%9A%84%E5%BC%95%E6%93%8E"><span class="nav-number">1.4.</span> <span class="nav-text">修改表的引擎</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E5%BC%95%E6%93%8E"><span class="nav-number">1.5.</span> <span class="nav-text">修改默认引擎</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MyISAM%E5%92%8CInnoDB%E5%8C%BA%E5%88%AB"><span class="nav-number">1.6.</span> <span class="nav-text">MyISAM和InnoDB区别</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Mysql%E7%B4%A2%E5%BC%95"><span class="nav-number">2.</span> <span class="nav-text">Mysql索引</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E7%B4%A2%E5%BC%95"><span class="nav-number">2.1.</span> <span class="nav-text">什么是索引</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B4%A2%E5%BC%95%E4%BC%98%E7%82%B9"><span class="nav-number">2.2.</span> <span class="nav-text">索引优点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A0%E7%B4%A2%E5%BC%95%E4%B8%8E%E4%B8%8D%E5%8A%A0%E7%B4%A2%E5%BC%95%E5%8C%BA%E5%88%AB"><span class="nav-number">2.3.</span> <span class="nav-text">加索引与不加索引区别</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B4%A2%E5%BC%95%E7%BC%BA%E7%82%B9"><span class="nav-number">2.4.</span> <span class="nav-text">索引缺点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%B4%A2%E5%BC%95%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.5.</span> <span class="nav-text">索引类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%99%BE%E4%B8%87%E7%BA%A7%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="nav-number">2.6.</span> <span class="nav-text">创建百万级数据表</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mysql%E5%BF%85%E5%A4%87%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E6%99%AE%E9%80%9A%E7%B4%A2%E5%BC%95%E4%B8%8E%E5%94%AF%E4%B8%80%E7%B4%A2%E5%BC%95"><span class="nav-number">2.7.</span> <span class="nav-text">mysql必备核心知识之普通索引与唯一索引</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E6%99%AE%E9%80%9A%E7%B4%A2%E5%BC%95%EF%BC%9F"><span class="nav-number">2.7.1.</span> <span class="nav-text">什么是普通索引？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%94%AF%E4%B8%80%E7%B4%A2%E5%BC%95%EF%BC%9F"><span class="nav-number">2.7.2.</span> <span class="nav-text">什么是唯一索引？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E6%99%AE%E9%80%9A%E7%B4%A2%E5%BC%95%E5%92%8C%E5%94%AF%E4%B8%80%E7%B4%A2%E5%BC%95%EF%BC%9F"><span class="nav-number">2.8.</span> <span class="nav-text">如何创建普通索引和唯一索引？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E7%B4%A2%E5%BC%95"><span class="nav-number">2.9.</span> <span class="nav-text">查看索引</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E7%B4%A2%E5%BC%95"><span class="nav-number">2.10.</span> <span class="nav-text">删除索引</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mysql%E5%BF%85%E5%A4%87%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%B8%BB%E9%94%AE%E7%B4%A2%E5%BC%95"><span class="nav-number">2.11.</span> <span class="nav-text">mysql必备核心知识之主键索引</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E4%B8%BB%E9%94%AE%E7%B4%A2%E5%BC%95"><span class="nav-number">2.11.1.</span> <span class="nav-text">什么是主键索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E4%B8%BB%E9%94%AE%E7%B4%A2%E5%BC%95"><span class="nav-number">2.11.2.</span> <span class="nav-text">创建主键索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E4%B8%BB%E9%94%AE"><span class="nav-number">2.11.3.</span> <span class="nav-text">删除主键</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#mysql%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-number">2.12.</span> <span class="nav-text">mysql核心知识之全文索引的使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95"><span class="nav-number">2.12.1.</span> <span class="nav-text">什么是全文索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B7%BB%E5%8A%A0%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95"><span class="nav-number">2.12.2.</span> <span class="nav-text">添加全文索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95"><span class="nav-number">2.12.3.</span> <span class="nav-text">使用全文索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9F%A5%E7%9C%8B%E5%8C%B9%E9%85%8D%E5%BA%A6"><span class="nav-number">2.12.4.</span> <span class="nav-text">查看匹配度</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%88%A0%E9%99%A4%E5%85%A8%E6%96%87%E7%B4%A2%E5%BC%95"><span class="nav-number">2.12.5.</span> <span class="nav-text">删除全文索引</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%81%9C%E6%AD%A2%E8%AF%8D"><span class="nav-number">2.12.6.</span> <span class="nav-text">停止词</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Carson Zhao"
      src="/hexo_blog/images/1.png">
  <p class="site-author-name" itemprop="name">Carson Zhao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo_blog/archives">
          <span class="site-state-item-count">59</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo_blog/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo_blog/tags/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/hexo_blog/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo_blog/images/1.png">
      <meta itemprop="name" content="Carson Zhao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Carson Zhao">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          mysql的存储引擎和索引
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-04-12 13:26:22" itemprop="dateCreated datePublished" datetime="2021-04-12T13:26:22+08:00">2021-04-12</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-04-19 11:58:23" itemprop="dateModified" datetime="2021-04-19T11:58:23+08:00">2021-04-19</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/hexo_blog/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>3 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="mysql的存储引擎介绍"><a href="#mysql的存储引擎介绍" class="headerlink" title="mysql的存储引擎介绍"></a>mysql的存储引擎介绍</h1><h2 id="什么是数据库存储引擎？"><a href="#什么是数据库存储引擎？" class="headerlink" title="什么是数据库存储引擎？"></a>什么是数据库存储引擎？</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">数据库底层软件组件，不同的引擎提供不同的存储方式，索引技巧。</span><br><span class="line">事务使用InnoDB</span><br></pre></td></tr></table></figure>

<h2 id="如何查看支持的引擎"><a href="#如何查看支持的引擎" class="headerlink" title="如何查看支持的引擎"></a>如何查看支持的引擎</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">show engines;</span><br><span class="line">查看当前表的引擎：</span><br><span class="line">show create table 表名\G</span><br><span class="line">查看所有表的引擎：</span><br><span class="line">show create table account\G</span><br></pre></td></tr></table></figure>

<h2 id="建表时指定引擎"><a href="#建表时指定引擎" class="headerlink" title="建表时指定引擎"></a>建表时指定引擎</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">create table 表名 &#123;&#125; engine&#x3D;&#39;InnoDB&#39;;</span><br></pre></td></tr></table></figure>

<h2 id="修改表的引擎"><a href="#修改表的引擎" class="headerlink" title="修改表的引擎"></a>修改表的引擎</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table 表名 engine&#x3D;&#39;MyiSAm&#39;</span><br></pre></td></tr></table></figure>

<h2 id="修改默认引擎"><a href="#修改默认引擎" class="headerlink" title="修改默认引擎"></a>修改默认引擎</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vi &#x2F;etc&#x2F;my.cnf</span><br><span class="line">default-storage-engine&#x3D;MyIsAM</span><br><span class="line">重启服务</span><br></pre></td></tr></table></figure>

<h2 id="MyISAM和InnoDB区别"><a href="#MyISAM和InnoDB区别" class="headerlink" title="MyISAM和InnoDB区别"></a>MyISAM和InnoDB区别</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">MyIASM不支持事务，支持全文索引，支持表级锁</span><br><span class="line">InnoDB支持事务，不支持全文索引（5.6之后支持），支持行级锁</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">一般不用事务，有很多count计算的用MyISAM</span><br><span class="line">可靠性要求高，要支持事务的使用InnoDB</span><br></pre></td></tr></table></figure>

<h1 id="Mysql索引"><a href="#Mysql索引" class="headerlink" title="Mysql索引"></a>Mysql索引</h1><h2 id="什么是索引"><a href="#什么是索引" class="headerlink" title="什么是索引"></a>什么是索引</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">一种单独存储在磁盘上的数据库结构，包含着对所有记录的引用指针，可以快速查找到数据（和目录一样）</span><br></pre></td></tr></table></figure>

<h2 id="索引优点"><a href="#索引优点" class="headerlink" title="索引优点"></a>索引优点</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">加快查询速度</span><br><span class="line">通过创建唯一索引，保证数据的唯一性</span><br></pre></td></tr></table></figure>

<h2 id="加索引与不加索引区别"><a href="#加索引与不加索引区别" class="headerlink" title="加索引与不加索引区别"></a>加索引与不加索引区别</h2><p><img src="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416185307875.png" alt="image-20210416185307875"></p>
<p><img src="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416185353831.png" alt="image-20210416185353831"></p>
<h2 id="索引缺点"><a href="#索引缺点" class="headerlink" title="索引缺点"></a>索引缺点</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">占用物理空间</span><br><span class="line">数据改动时，索引也要改动，增加了维护难度</span><br></pre></td></tr></table></figure>

<h2 id="索引类型"><a href="#索引类型" class="headerlink" title="索引类型"></a>索引类型</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">普通索引：index</span><br><span class="line">唯一索引：unique</span><br><span class="line">主键索引：primary key</span><br><span class="line">外键索引：foreign key</span><br><span class="line">全文索引：fulltext</span><br><span class="line">组合索引</span><br></pre></td></tr></table></figure>

<h2 id="创建百万级数据表"><a href="#创建百万级数据表" class="headerlink" title="创建百万级数据表"></a>创建百万级数据表</h2><ul>
<li>创建表的sql语句：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">create table test (</span><br><span class="line">    id int(7) zerofill auto_increment not null,</span><br><span class="line">    username varchar(20),</span><br><span class="line">    servnumber varchar(30),</span><br><span class="line">    password varchar(20),</span><br><span class="line">    createtime datetime,</span><br><span class="line">    primary key (id)</span><br><span class="line">)DEFAULT CHARSET&#x3D;utf8;</span><br></pre></td></tr></table></figure>

<ul>
<li>生成百万甚至千万级别表的sql 语句 shell脚本：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">#!&#x2F;bin&#x2F;bash</span><br><span class="line">echo &quot;请输入字段servnumber的值：&quot;</span><br><span class="line">read serber</span><br><span class="line">echo &quot;请输入创建sql语句的数量：&quot;</span><br><span class="line">read number</span><br><span class="line"># char&#x3D;&#96;head &#x2F;dev&#x2F;urandom | tr -dc 0-9 | head -c 11&#96;</span><br><span class="line">for (( i&#x3D;0;i&lt;$number;i++ ))</span><br><span class="line">        do</span><br><span class="line">        pass&#x3D;&#96;head &#x2F;dev&#x2F;urandom | tr -dc a-z | head -c 8&#96;</span><br><span class="line">        let serber&#x3D;serber+1</span><br><span class="line">        echo &quot;insert into test(id,username,servnumber,password,createtime) values(&#39;$i&#39;,&#39;user$&#123;i&#125;&#39;,&#39;$&#123;serber&#125;&#39;,&#39;$pass&#39;,now());&quot; &gt;&gt;sql.txt</span><br><span class="line">    done</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vi test.sh</span><br><span class="line">执行shell脚本：sh test.sh</span><br><span class="line">进行插数操作：source &#x2F;home&#x2F;dazhu&#x2F;sql.txt</span><br></pre></td></tr></table></figure>

<h2 id="mysql必备核心知识之普通索引与唯一索引"><a href="#mysql必备核心知识之普通索引与唯一索引" class="headerlink" title="mysql必备核心知识之普通索引与唯一索引"></a>mysql必备核心知识之普通索引与唯一索引</h2><h3 id="什么是普通索引？"><a href="#什么是普通索引？" class="headerlink" title="什么是普通索引？"></a>什么是普通索引？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">普通索引index，允许出现相同的索引内容，允许空值</span><br></pre></td></tr></table></figure>

<h3 id="什么是唯一索引？"><a href="#什么是唯一索引？" class="headerlink" title="什么是唯一索引？"></a>什么是唯一索引？</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">不能出现相同的索引内容，可以为空</span><br></pre></td></tr></table></figure>

<h2 id="如何创建普通索引和唯一索引？"><a href="#如何创建普通索引和唯一索引？" class="headerlink" title="如何创建普通索引和唯一索引？"></a>如何创建普通索引和唯一索引？</h2><ul>
<li>建表时创建</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">create table test (</span><br><span class="line">                        id int(7) zerofill auto_increment not null,</span><br><span class="line">                        username varchar(20),</span><br><span class="line">                        servnumber varchar(30),</span><br><span class="line">                        password varchar(20),</span><br><span class="line">                        createtime datetime,</span><br><span class="line">                        unique (id)      创建唯一索引</span><br><span class="line">                        index (id)       创建普通索引</span><br><span class="line">                  )DEFAULT CHARSET&#x3D;utf8;</span><br></pre></td></tr></table></figure>

<ul>
<li>直接为表添加索引</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">语法：</span><br><span class="line">     alter table 表名 add index 索引名称 (字段名称);</span><br><span class="line"> eg: </span><br><span class="line">     alter table test add unique unique_username (username);</span><br><span class="line">注意：假如没有指定索引名称时，会以默认的字段名为索引名称</span><br></pre></td></tr></table></figure>

<ul>
<li>直接创建索引</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">create index 索引名 on 表名 (字段名);</span><br><span class="line">eg：create index index_createtime on test (createtime);</span><br></pre></td></tr></table></figure>

<h2 id="查看索引"><a href="#查看索引" class="headerlink" title="查看索引"></a>查看索引</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">show index from 表名\G</span><br></pre></td></tr></table></figure>

<h2 id="删除索引"><a href="#删除索引" class="headerlink" title="删除索引"></a>删除索引</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">alter table 表名 drop index 索引名;</span><br><span class="line">或者 drop index 索引名 on 表名；</span><br></pre></td></tr></table></figure>

<h2 id="mysql必备核心知识之主键索引"><a href="#mysql必备核心知识之主键索引" class="headerlink" title="mysql必备核心知识之主键索引"></a>mysql必备核心知识之主键索引</h2><h3 id="什么是主键索引"><a href="#什么是主键索引" class="headerlink" title="什么是主键索引"></a>什么是主键索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">为主键添加索引，不允许为空，特殊的唯一索引</span><br></pre></td></tr></table></figure>

<h3 id="创建主键索引"><a href="#创建主键索引" class="headerlink" title="创建主键索引"></a>创建主键索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table test add primary key  (字段名)</span><br></pre></td></tr></table></figure>

<h3 id="删除主键"><a href="#删除主键" class="headerlink" title="删除主键"></a>删除主键</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">alter table test drop primary key;</span><br><span class="line">注意：在有自增的情况下，必须先删除自增，才可以删除主键</span><br><span class="line">删除自增：alter table test change id id int(7) unsigned zerofill not null;</span><br></pre></td></tr></table></figure>

<h2 id="mysql核心知识之全文索引的使用"><a href="#mysql核心知识之全文索引的使用" class="headerlink" title="mysql核心知识之全文索引的使用"></a>mysql核心知识之全文索引的使用</h2><h3 id="什么是全文索引"><a href="#什么是全文索引" class="headerlink" title="什么是全文索引"></a>什么是全文索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">全文索引是将存储在数据库中的文章或者句子等任意内容信息查找出来的索引，单位是词。全文索引也是目前搜索引擎使用的一种关键技术。指定为 fulltext</span><br></pre></td></tr></table></figure>

<ul>
<li>创建练习表的sql：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">create table command (</span><br><span class="line">id int(5) unsigned primary key  auto_increment,</span><br><span class="line">name varchar(10),</span><br><span class="line">instruction varchar(60)</span><br><span class="line">)engine&#x3D;MyISAM;</span><br></pre></td></tr></table></figure>

<ul>
<li>插入数据sql：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">insert into command values(&#39;1&#39;,&#39;ls&#39;,&#39;list directory contents&#39;);</span><br><span class="line">insert into command values(&#39;2&#39;,&#39;wc&#39;,&#39;print newline, word, and byte counts for each file&#39;);</span><br><span class="line">insert into command values(&#39;3&#39;,&#39;cut&#39;,&#39;remove sections from each line of files&#39;);</span><br><span class="line">insert into command values(&#39;4&#39;,&#39;sort&#39;,&#39;sort lines of text files&#39;);</span><br><span class="line">insert into command values(&#39;5&#39;,&#39;find&#39;,&#39;search for files in a directory hierarchy&#39;);</span><br><span class="line">insert into command values(&#39;6&#39;,&#39;cp&#39;,&#39;复制文件或者文件夹&#39;);</span><br><span class="line">insert into command values(&#39;7&#39;,&#39;top&#39;,&#39;display Linux processes&#39;);</span><br><span class="line">insert into command values(&#39;8&#39;,&#39;mv&#39;,&#39;修改文件名，移动&#39;);</span><br><span class="line">insert into command values(&#39;9&#39;,&#39;停止词&#39;,&#39;is,not,me,yes,no ...&#39;);</span><br></pre></td></tr></table></figure>

<h3 id="添加全文索引"><a href="#添加全文索引" class="headerlink" title="添加全文索引"></a>添加全文索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table command add fulltext(字段名);</span><br></pre></td></tr></table></figure>

<h3 id="使用全文索引"><a href="#使用全文索引" class="headerlink" title="使用全文索引"></a>使用全文索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">select * from 表名 match (添加了全文索引的字段名) against (&#39;检索内容&#39;)</span><br><span class="line">select * from command where match(instruction) against (&#39;sections&#39;);</span><br></pre></td></tr></table></figure>

<h3 id="查看匹配度"><a href="#查看匹配度" class="headerlink" title="查看匹配度"></a>查看匹配度</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select * from command where match(instruction) against (&#39;directory&#39;);</span><br></pre></td></tr></table></figure>

<h3 id="删除全文索引"><a href="#删除全文索引" class="headerlink" title="删除全文索引"></a>删除全文索引</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table command drop index 索引名</span><br></pre></td></tr></table></figure>

<h3 id="停止词"><a href="#停止词" class="headerlink" title="停止词"></a>停止词</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">出现频率很高的词，将会使全文索引失效，比如is，no，not，you，me，yes这些，我们称之为停止词</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Carson Zhao
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/" title="mysql的存储引擎和索引">https://bone-nails.gitee.io/2021/04/12/mysql的存储引擎和索引/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/hexo_blog/tags/%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/" rel="tag"># 存储引擎和索引</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/12/mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98/" rel="prev" title="mysql的核心知识之事务实战">
                  <i class="fa fa-chevron-left"></i> mysql的核心知识之事务实战
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/12/5-grep%E3%80%81sed%E3%80%81awk/" rel="next" title="5.grep、sed、awk">
                  5.grep、sed、awk <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Carson Zhao</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">125k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:54</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script size="300" alpha="0.6" zIndex="-1" src="https://cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/hexo_blog/js/utils.js"></script><script src="/hexo_blog/js/next-boot.js"></script>

  
<script src="/hexo_blog/js/local-search.js"></script>



<script>
if (document.querySelectorAll('.pdf-container').length) {
  NexT.utils.getScript('https://cdn.jsdelivr.net/npm/pdfobject@2.2.4/pdfobject.min.js', () => {
    document.querySelectorAll('.pdf-container').forEach(element => {
      PDFObject.embed(element.dataset.target, element, {
        pdfOpenParams: {
          navpanes : 0,
          toolbar  : 0,
          statusbar: 0,
          pagemode : 'thumbs',
          view     : 'FitH'
        },
        PDFJS_URL: '/hexo_blog/lib/pdf/web/viewer.html',
        height   : element.dataset.height
      });
    });
  }, window.PDFObject);
}
</script>


  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>

  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





<script src="/hexo_blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/hexo_blog/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":200,"height":400},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
